import com.zhan.frame.core.utils.FileUtils;
import java.io.File;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;

public class DealAudioZip {

  final static String ALL_AUDIO = "E:\\工作文档\\Test\\压缩包处理\\all_audio\\";
  final static String ZIP = "E:\\工作文档\\Test\\压缩包处理\\zip\\";
  final static String FINAL_ZIP = "E:\\工作文档\\Test\\压缩包处理\\final_zip\\";
  final static String TEMP = "E:\\工作文档\\Test\\压缩包处理\\temp\\";

  public static void main(String[] args) {
    List<String> list = ttt2();
        for (String name : list) {
      FileUtils.zipFile(ALL_AUDIO, FINAL_ZIP + name+"audio.zip", name+"*", null);
    }
//    File zipFile = new File(ZIP);
//    File[] zipFiles = zipFile.listFiles();
//    File allAudioFile = new File(ALL_AUDIO);
//    File[] audioFils = allAudioFile.listFiles();
//    List<String> names = new ArrayList<>();
//    for (File zf : audioFils) {
//      String fileName = zf.getName();
//      String[] tempArr = fileName.split("_");
//      String frontFix = tempArr[0] + "_" + tempArr[1] + "_*";
//
//      if(names.contains(frontFix)) {
//        continue;
//      }
//      names.add(frontFix);
//
//    }
//    System.out.println(names.toString());

//    for (String name : names) {
//      FileUtils.zipFile(ALL_AUDIO, FINAL_ZIP + name.replace("*", "audio.zip"), name, null);
//    }
//    ttt();

  }


  public static void ttt() {
    Map<String, List<String>> map = new HashMap();
    String path = "E:\\工作文档\\Test\\ielts_audios_all_new\\";
    File f = new File(path);
    File [] files = f.listFiles();
    for (File file : files) {
      String fileName = file.getName();
      if(fileName.contains("p1_")) {
        String[] tempArr = fileName.split("_");
        String frontFix = tempArr[0] + "_" + tempArr[1] + "_*";
        if (map.containsKey(frontFix)) {
          if (tempArr.length == 4) {
            map.get(frontFix).add(fileName);
          }
        } else {
          List<String> list = new ArrayList<>();
          if (tempArr.length == 4) {
            list.add(fileName);
          }
          map.put(frontFix, list);
        }
      }
    }

    Set<String> keySet = map.keySet();
    for (String key : keySet) {
      if(map.get(key).size() == 0) {
        System.out.println(key);
      }
    }
  }

  public static List<String> ttt2() {
    List<String> list = new ArrayList<>();
    String path = "C:\\Users\\Admin\\Desktop\\part1补充导语录音\\";
    File f = new File(path);
    File [] files = f.listFiles();
    for (File file : files) {
      String fileName = file.getName();
      if(fileName.contains("p1_")) {
        String[] tempArr = fileName.split("_");
        String frontFix = tempArr[0] + "_" + tempArr[1] + "_";
        if(!list.contains(frontFix)) {
          list.add(frontFix);
        }
      }
    }
    System.out.println(list.toString());
    return list;
  }
}